<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="com.are.odisea.*"%>
<%@ page import="java.util.*"%>
<%
	db conexion = null;
	String cedula = (String) request.getParameter("cedula");
	ArrayList<Stock> lista = new ArrayList<Stock>();
	int fila = 1;
	if (request.getParameter("criterio") != null) {
		conexion = new db();
		String criterio = (String) request.getParameter("criterio");
		String tipo = (String) request.getParameter("tipo");
		GestionStock gs = new GestionStock(conexion, cedula);
		int filter = Integer.parseInt(tipo);
		switch (filter) {
		case GestionStock.FILTER_BY_TERMINE:
			lista = gs.FindSeriales(criterio,
					GestionStock.FILTER_BY_CONTENGA);
			break;
		case GestionStock.FILTER_BY_COMIENCE:
			lista = gs.FindSeriales(criterio,
					GestionStock.FILTER_BY_COMIENCE);
		
			break;
		case GestionStock.FILTER_BY_CONTENGA:
			lista = gs.FindSeriales(criterio,
					GestionStock.FILTER_BY_TERMINE);

			break;

		}
	}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Buscar Serial</title>
<link rel="stylesheet" href="themes/redmond/jquery.ui.all.css">
<LINK REL="stylesheet" TYPE="text/css" HREF="main.css">
<script src="js/jquery.js" language="JavaScript"></script>
<script src="ui/jquery.ui.core.js" language="JavaScript"></script>
<script src="ui/jquery.ui.widget.js" language="JavaScript"></script>
<script src="ui/jquery.ui.button.js"></script>
<link rel="stylesheet" href="demos.css">

<script type="text/javascript">
$(function() {
	$( "input:submit, a, button", ".demo" ).button();
	$( "input:button, a, button", ".demo" ).button();
});
</script>
<script type="text/javascript">
	function validar() {
		var criterio = $("#criterio").val();
		if (criterio == "") {
			alert("Debe ingresar el criterio de busqueda");
			return false;
		}
		if (criterio.length < 3 ) {
			alert("El criterio tiene menos de 3 caracteres");
			return false;
		}
		return true;
	}
	
	
	function Aplicar(id) {
			$.post("SrvSerialOrden",{
				operacion: "add",
				id: id
			},procesar);
		
	}
	function procesar(result) {
		if (result == "OK") {
			alert("Serial Aplicado");
			window.opener.lista_seriales();
		}else {
			alert(result);
		}
	}

</script>
</head>

<body>
<div class="demo">
<h2>Mis equipos</h2>
	<form action="" onsubmit="return validar()">
		<table>
			<tr>
				<th>Buscar Serial <input type="hidden"
					name="cedula" value="<%=(String) request.getParameter("cedula")%>">
				</th>
			</tr>
			<tr>
				<td>Buscar por: 
					<input type="radio" name="tipo" value="3" checked>Contenga 
					<input type="radio" name="tipo" value="4">Comience
					<input type="radio" name="tipo" value="5">Termine
				</td>
			</tr>
			<tr>
				<td>Ingrese criterio: <input type="text" value=""
					name="criterio" id="criterio" size=40 /><input type="submit"
					value="Buscar" />
				</td>
			</tr>

		</table>

	</form>
	<%
		if (request.getParameter("criterio") != null) {
	%>
	<%
		if (lista.size() > 0) {
	%>
	<table>
		<tr>
			<th>Codigo</th>
			<th>Descripcion</th>
			<th>Unidad</th>
			<th>Bodega</th>
			<th>Suministro</th>
			<th>Centro</th>
			<th>Estado</th>
			<th>Num.Entrega</th>
			<th>Serial</th>
			<th>CAS-ID</th>
			<th>Accion</th>
		</tr>
		<%
			for (Stock stock : lista) {
		%>
		<tr <%=fila % 2 == 0 ? "class='odd'" : ""%>>
			<td><%=stock.getMaterial()%></td>
			<td><%=stock.getDesc_material()%></td>
			<td><%=stock.getUnd_material()%></td>
			<td><%=stock.getDesc_bodega()%></td>
			<td><%=stock.getSuministro()%></td>
			<td><%=stock.getDesc_centro()%></td>
			<td><%=stock.getDesc_estado()%></td>
			<td><%=stock.getNum_entrega()%></td>
			<td><%=stock.getSerial() %></td>
			<td><%=stock.getCasid() %></td>
			<td><input type="button" value="Aplicar" name="cmd_aplicar"
				onclick="javascript:Aplicar('<%=stock.getId()%>')"></td>
		</tr>
		<%
			fila++;
		%>
		<%
			}
		%>
		<tr>
			<th colspan="12">Total registros encontrados: <%=lista.size()%></th>
		</tr>
	</table>

	<%
		} else {
	%>
	<strong>No se encontraron registros con el criterio de
		busqueda</strong>
	<%
		}
	%>
	<%
		}
	%>
</div>
</body>
</html>
<%
	if (conexion != null) {
		conexion.Close();
	}
%>